package com.jerei.plugin.control;

import com.jerei.plugin.entity.WcmCommonMenuDetail;
import com.jerei.plugin.service.IWcmCommonMenuDetailService;
import com.jerei.web.plugin.controller.PluginController;
import com.jerei.web.utils.UtilsUI;
import com.jerei.web.utils.UtilsWeb;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import ro.fortsoft.pf4j.Extension;

/**
 * Created by sunfeihu on 2016/12/12.
 */
@Extension
public class MenuControl extends PluginController {

    @Autowired
    private IWcmCommonMenuDetailService iWcmCommonMenuDetailService;

    @RequiresPermissions({"common-menu:view"})
    public void menuList() {
        this.getModel().addAttribute("gid", UtilsWeb.getLong(this.getRequest(), "gid"));
    }

    @RequiresPermissions({"common-menu:view"})
    public String menuPage() {
        Long gid = UtilsWeb.getLong(this.getRequest(), "gid");
        Integer nowPage = UtilsWeb.getInteger(this.getRequest(), "page");
        Integer pageSize = UtilsWeb.getInteger(this.getRequest(), "rows");
        return UtilsUI.datagrid(iWcmCommonMenuDetailService.groupRootMenuDetail(nowPage, pageSize, gid));
    }

    @RequiresPermissions({"common-menu:save:*", "common-menu:update:*", "common-menu:view:*"})
    public void menuEdit() {
        Long id = UtilsWeb.getLong(this.getRequest(), "id");
        WcmCommonMenuDetail entity = null;
        if (null != id && id > 0L) {
            entity = iWcmCommonMenuDetailService.find(id);
        } else {
            Long pid = UtilsWeb.getLong(this.getRequest(), "pid");
            Long gid = UtilsWeb.getLong(this.getRequest(), "gid");
            entity = new WcmCommonMenuDetail();
            entity.setMenuNo(2);
            entity.setIsShow(1);
            entity.setGid(gid);
            if (null != pid && pid > 0) {
                entity.setPid(pid);
            }
        }
        this.getModel().addAttribute("obj", entity);
    }

}
